package com.pap.obj.vo.utils;

import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

/**
 * 字符串长度比较器 	 可以理解为最优字符串匹配
 * 	字符串长度长的在最前面，字符串长度相等的，则按照普通字符串进行比较，大的在前面
 * @author alexgaoyh
 *
 */
public class StringLengthComparator implements Comparator<String> {

	@Override
	public int compare(String s1, String s2) {
		int num = new Integer(s2.length()).compareTo(new Integer(s1.length()));
		if (num == 0) {
			return s2.compareTo(s1);// 字符串排序
		}
		return num;
	}
	
	public static void main(String[] args) {
		TreeSet<String> treeSet = new TreeSet<String>(new StringLengthComparator());
		treeSet.add("首付比例");
		treeSet.add("融资项目");
		treeSet.add("首付比例2");
		treeSet.add("融资项目3");
		treeSet.add("首付比例首付比例");

		for (Iterator<String> iter = treeSet.iterator(); iter.hasNext();) {
			String a = iter.next();
			System.out.println(a);
		}
		
	}

}